<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <!--            <el-form-item label="t_fertilizer_distributor_v1主键" prop="moduleId">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.moduleId"-->
            <!--                    placeholder="请输入t_fertilizer_distributor_v1主键"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <el-form-item label="通道号" prop="channelNum">
                <el-input
                    v-model="queryParams.channelNum"
                    placeholder="请输入通道号"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <!--            <el-form-item label="数据id" prop="dataId">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.dataId"-->
            <!--                    placeholder="请输入数据id"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="开始时间" prop="startTime">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.startTime"-->
            <!--                    placeholder="请输入开始时间"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="结束时间" prop="endTime">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.endTime"-->
            <!--                    placeholder="请输入结束时间"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <el-form-item label="起止时间">
                <myDateTime formatDate="timestamp" @changeDate="handleChangeDate" :selectDateValue="selectDateValue"></myDateTime>
            </el-form-item>

            <!--            <el-form-item label="加肥量" prop="addNum">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.addNum"-->
            <!--                    placeholder="请输入加肥量"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="加肥时间" prop="addTime">-->
            <!--                <el-input-->
            <!--                    v-model="queryParams.addTime"-->
            <!--                    placeholder="请输入加肥时间"-->
            <!--                    clearable-->
            <!--                    size="small"-->
            <!--                    @keyup.enter.native="handleQuery"-->
            <!--                />-->
            <!--            </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!--            <el-col :span="1.5">-->
            <!--                <el-button-->
            <!--                    type="primary"-->
            <!--                    plain-->
            <!--                    icon="el-icon-plus"-->
            <!--                    size="mini"-->
            <!--                    @click="handleAdd"-->
            <!--                    v-hasPermi="['report:fertilizerDistributorV1Log:add']"-->
            <!--                >新增-->
            <!--                </el-button>-->
            <!--            </el-col>-->
            <!--            <el-col :span="1.5">-->
            <!--                <el-button-->
            <!--                    type="success"-->
            <!--                    plain-->
            <!--                    icon="el-icon-edit"-->
            <!--                    size="mini"-->
            <!--                    :disabled="single"-->
            <!--                    @click="handleUpdate"-->
            <!--                    v-hasPermi="['report:fertilizerDistributorV1Log:edit']"-->
            <!--                >修改-->
            <!--                </el-button>-->
            <!--            </el-col>-->
            <!--            <el-col :span="1.5">-->
            <!--                <el-button-->
            <!--                    type="danger"-->
            <!--                    plain-->
            <!--                    icon="el-icon-delete"-->
            <!--                    size="mini"-->
            <!--                    :disabled="multiple"-->
            <!--                    @click="handleDelete"-->
            <!--                    v-hasPermi="['report:fertilizerDistributorV1Log:remove']"-->
            <!--                >删除-->
            <!--                </el-button>-->
            <!--            </el-col>-->
            <!--            <el-col :span="1.5">-->
            <!--                <el-button-->
            <!--                    type="warning"-->
            <!--                    plain-->
            <!--                    icon="el-icon-download"-->
            <!--                    size="mini"-->
            <!--                    @click="handleExport"-->
            <!--                    v-hasPermi="['report:fertilizerDistributorV1Log:export']"-->
            <!--                >导出-->
            <!--                </el-button>-->
            <!--            </el-col>-->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="fertilizerDistributorV1LogList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <!--            <el-table-column label="${comment}" align="center" prop="id"/>-->
            <!--            <el-table-column label="t_fertilizer_distributor_v1主键" align="center" prop="moduleId"/>-->
            <el-table-column label="通道号" align="center" prop="channelNum"/>
            <!--            <el-table-column label="数据id" align="center" prop="dataId"/>-->
            <el-table-column label="开始时间" align="center" prop="startTime"/>
            <el-table-column label="结束时间" align="center" prop="endTime"/>
            <el-table-column label="加肥量" align="center" prop="addNum"/>
            <el-table-column label="加肥时间" align="center" prop="addTime"/>
            <!--            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <el-button-->
            <!--                        size="mini"-->
            <!--                        type="text"-->
            <!--                        icon="el-icon-edit"-->
            <!--                        @click="handleUpdate(scope.row)"-->
            <!--                        v-hasPermi="['report:fertilizerDistributorV1Log:edit']"-->
            <!--                    >修改-->
            <!--                    </el-button>-->
            <!--                    <el-button-->
            <!--                        size="mini"-->
            <!--                        type="text"-->
            <!--                        icon="el-icon-delete"-->
            <!--                        @click="handleDelete(scope.row)"-->
            <!--                        v-hasPermi="['report:fertilizerDistributorV1Log:remove']"-->
            <!--                    >删除-->
            <!--                    </el-button>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />

        <!-- 添加或修改施肥机v1历史记录对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="t_fertilizer_distributor_v1主键" prop="moduleId">
                    <el-input v-model="form.moduleId" placeholder="请输入t_fertilizer_distributor_v1主键"/>
                </el-form-item>
                <el-form-item label="通道号" prop="orderNum">
                    <el-input v-model="form.orderNum" placeholder="请输入通道号"/>
                </el-form-item>
                <el-form-item label="数据id" prop="dataId">
                    <el-input v-model="form.dataId" placeholder="请输入数据id"/>
                </el-form-item>
                <el-form-item label="开始时间" prop="startTime">
                    <el-input v-model="form.startTime" placeholder="请输入开始时间"/>
                </el-form-item>
                <el-form-item label="结束时间" prop="endTime">
                    <el-input v-model="form.endTime" placeholder="请输入结束时间"/>
                </el-form-item>
                <el-form-item label="加肥量" prop="addNum">
                    <el-input v-model="form.addNum" placeholder="请输入加肥量"/>
                </el-form-item>
                <el-form-item label="加肥时间" prop="addTime">
                    <el-input v-model="form.addTime" placeholder="请输入加肥时间"/>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {
    listFertilizerDistributorV1Log,
    getFertilizerDistributorV1Log,
    delFertilizerDistributorV1Log,
    addFertilizerDistributorV1Log,
    updateFertilizerDistributorV1Log
} from '@/api/report/fertilizerDistributorV1Log'
import myDateTime from '@/components/MyComponents/myDateTime/index.vue'

export default {
    name: 'FertilizerDistributorV1Log',
    components: { myDateTime },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 施肥机v1历史记录表格数据
            fertilizerDistributorV1LogList: [],
            // 弹出层标题
            title: '',
            selectDateValue:[],
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                moduleId: null,
                channelNum: null,
                dataId: null,
                startTimestamp: null,
                endTimestamp: null,
                selectDateValue:[],
                addNum: null,
                addTime: null
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
            moduleId: null
        }
    },
    created() {
        const moduleId = this.$route.params && this.$route.params.moduleId
        if (moduleId) {
            this.moduleId = moduleId
            this.queryParams.moduleId = moduleId
            this.getList()
        }
    },
    methods: {

        getList() {
            this.loading = true
            listFertilizerDistributorV1Log(this.queryParams).then(response => {
                this.fertilizerDistributorV1LogList = response.rows
                this.total = response.total
                this.loading = false
            })
        },

        cancel() {
            this.open = false
            this.reset()
        },
        // 日期
        handleChangeDate(val) {
            // console.log(val);
            if (val !== null) {
                this.queryParams.startTimestamp = val[0]
                this.queryParams.endTimestamp = val[1]
            }else {
                this.queryParams.startTimestamp = null
                this.queryParams.endTimestamp = null
            }
        },
        reset() {
            this.form = {
                id: null,
                moduleId: null,
                orderNum: null,
                dataId: null,
                startTimestamp: null,
                endTimestamp: null,
                selectDateValue:[],
                addNum: null,
                addTime: null
            }
            this.resetForm('form')
        },

        handleQuery() {
            console.log(this.queryParams)
            this.queryParams.pageNum = 1
            this.getList()
        },

        resetQuery() {
            this.resetForm('queryForm')
            this.queryParams.startTimestamp = null
            this.queryParams.endTimestamp = null
            this.handleQuery()
        },

        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },

        handleAdd() {
            this.reset()
            this.open = true
            this.title = '添加施肥机v1历史记录'
        },

        handleUpdate(row) {
            this.reset()
            const id = row.id || this.ids
            getFertilizerDistributorV1Log(id).then(response => {
                this.form = response.data
                this.open = true
                this.title = '修改施肥机v1历史记录'
            })
        },

        submitForm() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateFertilizerDistributorV1Log(this.form).then(response => {
                            this.$modal.msgSuccess('修改成功')
                            this.open = false
                            this.getList()
                        })
                    } else {
                        addFertilizerDistributorV1Log(this.form).then(response => {
                            this.$modal.msgSuccess('新增成功')
                            this.open = false
                            this.getList()
                        })
                    }
                }
            })
        },

        handleDelete(row) {
            const ids = row.id || this.ids
            this.$modal.confirm('是否确认删除施肥机v1历史记录编号为"' + ids + '"的数据项？').then(function() {
                return delFertilizerDistributorV1Log(ids)
            }).then(() => {
                this.getList()
                this.$modal.msgSuccess('删除成功')
            }).catch(() => {
            })
        },

        handleExport() {
            this.download('report/fertilizerDistributorV1Log/export', {
                ...this.queryParams
            }, `fertilizerDistributorV1Log_${new Date().getTime()}.xlsx`)
        }
    }
}
</script>
